﻿using Caliburn.Micro;
using Microsoft.Phone.Controls;
using Ninject.Modules;
using Spotted.Data.Repositories;
using Spotted.Data.Repositories.Impl;

namespace Spotted.Core
{
    public class SpottedNinjectModule : NinjectModule
    {
        private readonly PhoneApplicationFrame _rootFrame;

        public SpottedNinjectModule(PhoneApplicationFrame rootFrame)
        {
            _rootFrame = rootFrame;
        }

        #region Overrides of NinjectModule

        /// <summary>
        /// Loads the module into the kernel.
        /// </summary>
        public override void Load()
        {
            // phone services
            Bind<IWindowManager>().To<WindowManager>().InSingletonScope();
            Bind<INavigationService>().ToConstant(new FrameAdapter(_rootFrame)).InSingletonScope();
            Bind<IEventAggregator>().To<EventAggregator>().InSingletonScope();
            Bind<IPhoneService>().ToConstant(new PhoneApplicationServiceAdapter(_rootFrame)).InSingletonScope();
            Bind<IAppService>().ToConstant(new SpottedAppService(_rootFrame)).InSingletonScope();

            // repositories
            Bind<IPlacesRepository>().To<RestGooglePlacesRepository>().InSingletonScope();
            Bind<IMapsRepository>().To<RestGoogleMapsRepository>().InSingletonScope();
            Bind<ISpotRepository>().To<RestJsonSpotRepository>().InSingletonScope();
            Bind<IUserRepository>().To<RestJsonUserRepository>().InSingletonScope();
        }

        #endregion
    }
}
